package 美国疫情;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class MapTest extends Mapper<LongWritable, Text, JavaBean, NullWritable> {
    JavaBean k = new JavaBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        try {
            String[] datas = value.toString().split("\t", -1);
            for (String data : datas) {
                if (data == null || "".equals(data)) return;
            }
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/mm/dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-mm-dd");
            String date = sdf2.format(sdf1.parse(datas[0]));
            k.set(date, datas[1], datas[2], datas[3], Integer.parseInt(datas[4]), Integer.parseInt(datas[5]));
            context.write(k, NullWritable.get());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
